<template>
  <a-modal v-model:visible="visible" @ok="handleOk" @cancel="handleCancel">
    <template #title>
      新建文件夹
    </template>
    <a-form ref="formRef" :model="form" auto-label-width class="w-full">
      <a-form-item label="文件夹名称" field="name" :rules="[{ required: true, message: '请输入文件夹名称' }]"
        style="margin-bottom: 0">
        <a-input v-model="form.name" placeholder="文件夹名称" allow-clear />
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script setup>
import { ref } from 'vue'
import { fileAddDir } from '@/apis/file'
import { Message } from '@arco-design/web-vue'

const visible = ref(false)

const form = ref({
  name: '',
  parentId: 0
})

const open = (parentId) => {
  form.value = {
    name: ''
  }
  if (parentId) {
    form.value.parentId = parentId
  }
  visible.value = true
}

const emit = defineEmits(['success'])

const handleOk = async () => {
  console.log("form", form.value)
  const res = await fileAddDir(form.value)
  if (res) {
    Message.success('创建成功')
    emit('success')
  } else {
    Message.error('创建失败')
  }
  visible.value = false

}

const handleCancel = () => {
  visible.value = false
}





defineExpose({
  open
})


</script>